from barbican_gateway import *
import os

# VN_ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..'))
# print(VN_ROOT)
hft_setting = {
    "inst_type": "SPOT",
    "subscribe_codes": [
        "BTSE.SPOT.LTC-USDT.DEPTH1",
        "BTSE.SPOT.LTC-USDT.TRADES"
        # "BTSE.SPOT.BTSE-USDT.DEPTH20",
        # "BTSE.SPOT.BTSE-USDT.TRADES",
        # "BTSE.SPOT.BTSE-USDT.DEPTH1"
        # "UNISWAP.SPOT.BTSE-ETH.DEPTH1"

    ],
    "balance_codes": ["LTC", "USDT"],
    "trader": "yn",
    "strategyId": "yn_spot",
    "accountId": "joelin",
    "bbc_config_path": "/home/yinan.chen/barbican_spotmm_b/prod/LTC/.vntrader/bbc_config.json"
}
# hft_setting = {
#     "inst_type": "SPOT",
#     "subscribe_codes": [
#         "BTSE.SPOT.BTSE-USDT.DEPTH1",
#         "BTSE.SPOT.BTSE-USDT.TRADES"
#         # "BTSE.SPOT.BTSE-USDT.DEPTH20",
#         # "BTSE.SPOT.BTSE-USDT.TRADES",
#         # "BTSE.SPOT.BTSE-USDT.DEPTH1"
#         # "UNISWAP.SPOT.BTSE-ETH.DEPTH1"
#
#     ],
#     "balance_codes": ["BTSE", "USDT"],
#     "trader": "yn",
#     "strategyId": "yn_spot",
#     "accountId": "ynmm",
#     "bbc_config_path": "/home/yinan.chen/barbican_spotmm_b/prod/LTC/.vntrader/bbc_config.json"
# }
event_engine = EventEngine()
bbc = BBCGateway(event_engine)
bbc.connect(hft_setting)
# OrderTradeData(gateway_name='BBC', symbol='LTC-USDT', exchange=<Exchange.BTSE: 'BTSE'>, orderid='1729779733786627429', order=None, trade=None, type=<OrderType.MAKER: '做市'>, direction=<Direction.SHORT: 'SHORT'>, offset=<Offset.NONE: ''>, price=70.0, volume=1.0, traded=0.0, trade_diff=None, trade_price=0.0, status=<Status.NOTTRADED: 'NOTTRADED'>, exchange_status=<Status.NOTTRADED: 'NOTTRADED'>, insert=1729779733802542.0, update=1729779734556000.0, tsSent=0, tsNet=0, api_source=<ApiSource.WEBSOCKET: 'WEBSOCKET'>, is_maker=False, reduce_only=False, error_id=0, error_msg=None, reference='', query_num=0, cancel_num=0, latest_cancel_time=0, latest_query_time=0)
# OrderTradeData(gateway_name='BBC', symbol='LTC-USDT', exchange=<Exchange.BTSE: 'BTSE'>, orderid='1729779843829243512', order=None, trade=None, type=<OrderType.MAKER: '做市'>, direction=<Direction.LONG: 'LONG'>, offset=<Offset.NONE: ''>, price=69.0, volume=1.0, traded=0.0, trade_diff=None, trade_price=0.0, status=<Status.NOTTRADED: 'NOTTRADED'>, exchange_status=<Status.NOTTRADED: 'NOTTRADED'>, insert=1729779843830793.0, update=1729779844347000.0, tsSent=0, tsNet=0, api_source=<ApiSource.WEBSOCKET: 'WEBSOCKET'>, is_maker=False, reduce_only=False, error_id=0, error_msg=None, reference='', query_num=0, cancel_num=0, latest_cancel_time=0, latest_query_time=0)
# 0 获取合约
# instrument_info = bbc.query_smc(ExchangeType.BINANCE, InstType.USDT_SWAP, "KAS-USDT")
# 1. 测试订阅,行情,trade
# req = SubscribeRequest(symbol='LTC-USDT', exchange=Exchange.BTSE)
# bbc.subscribe(req)
# 2. 测试报查撤
# req = OrderRequest(symbol="LTC-USDT", exchange=Exchange.BTSE, direction=Direction.LONG, type=OrderType.LIMIT, offset=Offset.OPEN, volume=1, price=70)
# bbc.send_order(req)

# orderid = "1729857787728529327"
# cancel_req = CancelRequest(orderid=orderid, symbol="LTC-USDT", exchange=Exchange.BTSE)
# bbc.cancel_order(cancel_req)
# bbc.query_order(cancel_req)

# req = CancelAllRequest(symbol="LTC-USDT", exchange=Exchange.BTSE, product=Product.SPOT)
# bbc.cancel_all_orders(req)
# 对一下时间
# 3. 测试各种get
# c = bbc.get_spot_order_book(symbol="BTSE-USDT", exchange="BTSE")
# ask, bid = bbc.get_bbo("BTSE-ETH", "UNISWAP")
# print(ask, bid)
# refer_price = bbc.get_trades("ETH-USDT", "BTSE")
# print(refer_price)
# p_dex = (ask[0] + bid[0]) / 2 * refer_price
# print(p_dex)

ask, bid = bbc.get_bbo("LTC-USDT", "BTSE")
print(ask, bid)

# print(c)
# 4.timer
# 5. query_all
# req = QueryOpenOrderRequest(symbol="LTC-USDT", exchange=Exchange.BTSE, product = Product.SPOT)
# bbc.query_open_orders(req)

# 6.各种dex price
# dex_vt_symbol = "BTSE-ETH.UNISWAP"
# refer_vt_symbol = "ETH-USDT.BTSE"
# ask, bid = bbc.get_bbo(dex_vt_symbol.split(".")[0], dex_vt_symbol.split(".")[1])
# refer_price = bbc.get_trades(refer_vt_symbol.split(".")[0], refer_vt_symbol.split(".")[1])
# print(ask)
# print(bid)
# print(refer_price)
# p_dex = (ask[0] + bid[0]) / 2 * refer_price
